/**
 * Copyright (C) 2013 SHANGHAI VOLKSWAGEN, All rights reserved.
 * License version 1.0, a copy of which has been included with this.
 *
 * @File name：com.market.cart.server.config.CartThreadPoolConfig
 * @Create on：2024/3/6
 * @Author：liuchang
 */
package com.market.test.common.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * <p>ClassName：CartThreadPoolConfig</p >
 * <p>Description：</p >
 * <p>Author：liuchang</p >
 * <p>Date：2024/3/6</p >
 */
@Configuration
public class CartThreadPoolConfig {
    @Bean(name = "cartThreadPoolExecutor")
    public ThreadPoolExecutor cartThreadPoolExecutor(CartThreadPoolProperties cartThreadPoolProperties){
       return new ThreadPoolExecutor(
               cartThreadPoolProperties.getCorePoolSize(),
               cartThreadPoolProperties.getMaxPoolSize(),
               cartThreadPoolProperties.getKeepAliveTime(),
               TimeUnit.MINUTES,
               new LinkedBlockingDeque<>(cartThreadPoolProperties.getQueueCapacity()),
               Executors.defaultThreadFactory(),
               new ThreadPoolExecutor.AbortPolicy()
       );
    }
}
